-- Assignment 2
-- Indication of time spent: 9 man hours
module TestSTAL

where

import STAL
import SetEq

import Data.List
import Test.QuickCheck

-- Util function
set2list :: Set a -> [a]
set2list (Set x) = x

instance (Eq a, Arbitrary a) => Arbitrary (Set a) 
  where
    arbitrary = do 
                  xs <- listOf arbitrary; 
                  return (Set (nub xs))

main :: IO ()
main = do
  quickCheck prop_list2set
  quickCheck prop_not_empty
  quickCheck prop_in_set
  quickCheck prop_powerset
  quickCheck prop_take_set

prop_list2set xs = (length xs) > 0 
                 ==> length ((findIndices (==(head xs))) (set2list (list2set xs))) == 1
  where types = xs::[Integer]

prop_not_empty (Set xs) = length xs > 0 ==> not (isEmpty (Set xs))
  where types = (Set xs)::Set Integer

prop_in_set :: Integer -> Set Integer -> Bool
prop_in_set x (Set xs) = inSet x (list2set (x:xs))

-- Set can only be 12 long since very long lists will take too long to test.
prop_powerset (Set xs) = length xs < 12 ==> inSet (Set xs) (powerSet (Set xs))
  where types = (Set xs)::Set Integer

prop_take_set :: Set Integer -> Bool
prop_take_set (Set xs) = takeSet (length xs) (Set xs) == (Set xs)
